import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-06
 * Time: 23:39
 */
class Solution2 {
    public int[] sortArray(int[] nums) {
        qsort(nums,0,nums.length-1);
        return nums;
    }

    void qsort(int[] nums,int l,int r) {
        if(l >= r) return;

        int key = nums[new Random().nextInt(r-l+1)+l];
        int left = l-1 , right = r+1, i = l;

        while(i < right) {
            if(nums[i] < key) {
                swap(nums,++left,i++);
            }else if(nums[i] == key) {
                i++;
            }else {
                swap(nums,--right,i);
            }
        }

        qsort(nums,l,left);
        qsort(nums,right,r);
    }

    void swap(int[] nums,int i ,int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
